package com.qianbao.qianbaobusiness.ui.invoice;

import com.androidbase.base.mvp.RxMvpPresenter;
import com.androidbase.utils.RxUtils;
import com.baseandroid.config.ContractApi;
import com.baseandroid.retrofit.RxObserver;
import com.baseandroid.retrofit.json.Data;
import com.qianbao.qianbaobusiness.json.ContractListBean;

import java.util.List;

import javax.inject.Inject;

/**
 * @author: Routee
 * @date 2018/6/20
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class ContractListPresenter extends RxMvpPresenter<ContractListView> {
    ContractApi mApi;

    @Inject
    public ContractListPresenter(ContractApi api) {
        mApi = api;
    }

    public void getContractList(String merchantNo) {
        mApi.getContractList(merchantNo).compose(RxUtils.applySchedulersLifeCycle(getView()))
                .subscribe(new RxObserver<Data<List<ContractListBean.ResultBean>>>() {
                    @Override
                    public void onNext(Data<List<ContractListBean.ResultBean>> data) {
                        super.onNext(data);
                        if (RxObserver.checkJsonCode(data, false)) {
                            getView().getContractListSuccess(data.getResult());
                        } else {
                            getView().onNetError();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        getView().onNetError();
                    }
                });
    }
}
